//
//  LSChatCircleCell.m
//  LookScore
//
//  Created by wr on 2017/12/11.
//  Copyright © 2017年 ChongQingXunTiCompany. All rights reserved.
//
#define controlWidth (LSScreenWidth-LSSpaceLeftWidth1*2-20)/3

#import "LSChatCircleCell.h"
#import "LSChatPhotoView.h"
#import "LSChatCircleModel.h"

#import "NSString+JKSize.h"
@interface LSChatCircleCell()

@property(strong,nonatomic)UIImageView *headImageView;

@property(strong,nonatomic)UILabel *nameLab;

@property(strong,nonatomic)UILabel *introduceLab;

@property(strong,nonatomic)UILabel *timeLab;

@property(strong,nonatomic)UIButton *adressBu;

@property(strong,nonatomic)UIButton *browseBu;

@property(strong,nonatomic)UIButton *commentBu;

@property(strong,nonatomic)UIButton *praiseBu;

@property(nonatomic, strong) LSChatPhotoView * photoView;

@end
@implementation LSChatCircleCell

+(LSChatCircleCell *)ChatCircleTableViewCellByTableView:(UITableView *)tableView{
    
    LSChatCircleCell *cell=[tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    if (!cell) {
        cell=[[LSChatCircleCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self addContentView];
    }
    
    return self;
}

-(void)addContentView{
    
    UIImageView *headImageView=[[UIImageView alloc]init];
    headImageView.layer.masksToBounds=YES;
    headImageView.layer.cornerRadius=5;
    [self.contentView addSubview:headImageView];
    headImageView.userInteractionEnabled=YES;
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ClickedImageView:)];
    [headImageView addGestureRecognizer:tap];
    
    self.headImageView=headImageView; headImageView.sd_layout.leftEqualToView(self.contentView).offset(LSSpaceLeftWidth1).topEqualToView(self.contentView).offset(12).widthIs(30).heightIs(30);
    
    UILabel *nameLab=[[UILabel alloc]init];
    nameLab.font=LSFontSize11;
    nameLab.textColor=LSTitleGrayColor3;
    nameLab.textAlignment=NSTextAlignmentLeft;
    [self.contentView addSubview:nameLab];
    self.nameLab=nameLab;
    nameLab.sd_layout
    .leftSpaceToView(headImageView, 7)
    .centerYEqualToView(headImageView)
    .heightIs(20);
    [nameLab setSingleLineAutoResizeWithMaxWidth:120];
    
    
    UIButton *reportBu=[[UIButton alloc]init];
    [reportBu setImage:[UIImage imageNamed:@"delete"] forState:UIControlStateNormal];
//    [attentionBu setImage:[UIImage imageNamed:@"selectAttend"] forState:UIControlStateSelected];
    
    [reportBu addTarget:self action:@selector(reportEvent:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:reportBu];
    self.reportBu=reportBu;
    reportBu.sd_layout
    .rightEqualToView(self.contentView).offset(-LSSpaceLeftWidth1)
    .centerYEqualToView(headImageView)
    .widthIs(20)
    .heightIs(20);
    
    UILabel *introduceLab=[[UILabel alloc]init];
    introduceLab.font=LSFontSize15;
    introduceLab.textColor = LSSubColor5D5D5D;
    introduceLab.textAlignment=NSTextAlignmentLeft;
    introduceLab.numberOfLines=2;
    [self.contentView addSubview:introduceLab];
    self.introduceLab=introduceLab;
    introduceLab.sd_layout.leftEqualToView(headImageView).topSpaceToView(headImageView,14).rightEqualToView(self.contentView).offset(-LSSpaceLeftWidth1).heightIs(40);
    
    
//    UIView *backView=[[UIView alloc]init];
//    backView.backgroundColor=LSTitleWhiteColor;
//    [self.contentView addSubview:backView];
//    backView.sd_layout.leftEqualToView(headImageView).topSpaceToView(introduceLab, 9).rightEqualToView(self.contentView).offset(-LSSpaceLeftWidth1).heightIs(80);
    _photoView = [[LSChatPhotoView alloc] init];
//    KWeakSelf(self)
    
    [self.contentView addSubview:_photoView];
    _photoView.sd_layout
    .leftEqualToView(headImageView)
    .topSpaceToView(_introduceLab, 5); // 已经在内部实现宽度和高度自适应所以不需要再设置宽度高度，top值是具体有无图片在setModel方法中设置
    
    UIButton *adressBu=[UIButton new];
    [adressBu setTitleColor:RGB(255,158,68) forState:UIControlStateNormal];
    adressBu.titleLabel.font=LSFontSize9;
    adressBu.layer.cornerRadius=5;
    adressBu.layer.masksToBounds=YES;
    adressBu.layer.borderColor=RGB(255,158,68).CGColor;
    adressBu.layer.borderWidth=.5f;
    [self.contentView addSubview:adressBu];
    self.adressBu=adressBu;
    adressBu.sd_layout
    .leftEqualToView(headImageView)
    .topSpaceToView(_photoView,9)
    .widthIs(45)
    .heightIs(18);
    
    
    EdgeInsetsLabel * gameLabel = [[EdgeInsetsLabel alloc] init];
    gameLabel.textColor = Color(242, 94, 89);
    gameLabel.font = LSFontSize(10, LSScreenWidth);
    gameLabel.textAlignment = NSTextAlignmentCenter;
    gameLabel.text = @"皇家马德里 vs 毕尔巴鄂竞技";
    _gameLabel = gameLabel;
    gameLabel.layer.cornerRadius = 3;
    gameLabel.layer.borderColor = Color(242, 94, 89).CGColor;
    gameLabel.layer.borderWidth = 0.5;
    [self.contentView addSubview:gameLabel];
    gameLabel.sd_layout
    .leftSpaceToView(adressBu, 5)
    .centerYEqualToView(adressBu)
    .heightIs(18);
//    [gameLabel setSingleLineAutoResizeWithMaxWidth:180];
    gameLabel.contentInset = UIEdgeInsetsMake(3,3, 3, 3);
//    UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)
    
    UILabel *timeLab=[[UILabel alloc]init];
    timeLab.font=LSFontSize10;
    timeLab.textColor=LSTitleGrayColor3;
    timeLab.textAlignment=NSTextAlignmentLeft;
    [self.contentView addSubview:timeLab];
    
    self.timeLab=timeLab;
    timeLab.sd_layout
    .leftSpaceToView(nameLab, 7)
    .centerYEqualToView(nameLab)
    .heightIs(20);
    [self.timeLab setSingleLineAutoResizeWithMaxWidth:180];
    
    
    UIButton *browseBu=[UIButton new];
    [browseBu setTitleColor:LSTitleGrayColor3 forState:UIControlStateNormal];
    [browseBu setImage:[UIImage imageNamed:@"ChatBrowse"] forState:UIControlStateNormal];
    browseBu.titleLabel.font=LSFontSize10;
    [browseBu setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, -10)];
    [self.contentView addSubview:browseBu];
    self.browseBu=browseBu;
   
    
    UIButton *commentBu=[UIButton new];
    [commentBu setTitleColor:LSTitleGrayColor3 forState:UIControlStateNormal];
    [commentBu setImage:[UIImage imageNamed:@"ChatComment"] forState:UIControlStateNormal];
    commentBu.titleLabel.font=LSFontSize10;
     [commentBu setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, -10)];
    [self.contentView addSubview:commentBu];
    self.commentBu=commentBu;
   
    
    UIButton *praiseBu=[UIButton new];
    [praiseBu setTitleColor:LSTitleGrayColor3 forState:UIControlStateNormal];
    [praiseBu setImage:[UIImage imageNamed:@"ChatPraise"] forState:UIControlStateNormal];
    praiseBu.titleLabel.font=LSFontSize10;
     [praiseBu setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, -10)];
    [self.contentView addSubview:praiseBu];
    self.praiseBu=praiseBu;
    praiseBu.sd_layout
    .rightEqualToView(self.contentView).offset(-LSSpaceLeftWidth1)
    .centerYEqualToView(adressBu)
    .heightIs(25)
    .widthIs(50);
//    [praiseBu set]
    
    
    commentBu.sd_layout
    .rightSpaceToView(praiseBu, -7)
    .centerYEqualToView(adressBu)
    .widthIs(50)
    .heightIs(25);
    
     browseBu.sd_layout
    .rightSpaceToView(commentBu, -7)
    .centerYEqualToView(adressBu)
    .widthIs(50)
    .heightIs(25);

    UIView * bottomView = [[UIView alloc] init];
    bottomView.backgroundColor = LSBackGroundColor;
    [self.contentView addSubview:bottomView];
    bottomView.sd_layout
    .leftEqualToView(self.contentView)
    .rightEqualToView(self.contentView)
    .topSpaceToView(self.adressBu, 10)
    .heightIs(10);
    
   [self setupAutoHeightWithBottomView:bottomView bottomMargin:0];
    
}

- (void)setModel:(LSChatCircleModel *)model{
    _model = model;
    if (model.ImgUrlStr.length <= 0) {
       
        self.photoView.picPathStringsArray = @[];
//      self.adressBu.sd_resetLayout.leftEqualToView(self.headImageView).topSpaceToView(self.introduceLab,9).widthIs(60).heightIs(20);
//        self.photoView.hidden = YES;
    }else{
        NSArray * array = [model.ImgUrlStr componentsSeparatedByString:@","];
        self.photoView.picPathStringsArray = array;
    }
    self.adressBu.sd_resetLayout.leftEqualToView(self.headImageView).topSpaceToView(self.photoView,9).widthIs(60).heightIs(20);
    

//    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:model.UserHeadUrl] placeholderImage:[UIImage imageNamed:@"MineDefaultHead"] options:SDWebImageRefreshCached];

//    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:model.UserHeadUrl] placeholderImage:[UIImage imageNamed:@"MineDefaultHead"]];
    
//    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:model.UserHeadUrl] placeholderImage:[UIImage imageNamed:@"MineDefaultHead"] options:SDWebImageRefreshCached completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
//        
//    }];
    
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:model.UserHeadUrl] placeholderImage:[UIImage imageNamed:@"MineDefaultHead"] options:SDWebImageRefreshCached];

    self.nameLab.text = model.UserDisName;
    
    self.introduceLab.text = model.TopicContent;
    
    [self.adressBu setTitle:model.CircleName forState:UIControlStateNormal];
    NSString * timeStr = [model.CreateTime stringByReplacingOccurrencesOfString:@"T" withString:@" "];
    
    NSDateFormatter * df = [[NSDateFormatter alloc] init];
    df.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    NSString * dateString1 = timeStr;
    NSString * dateString2 = [CommonClass getCurrentTimes];
    NSDate * date1 = [df dateFromString:dateString1];
    NSDate * date2 = [df dateFromString:dateString2];
    NSTimeInterval time = [date2 timeIntervalSinceDate:date1]; //date1是前一个时间(早)，date2是后一个时间(晚)
    // 结果就是两个时间点之间相差的秒数，如果要精确时间，修改NSDateFormatter的形式，并把两个时间对应调整就行
    if (time < 300) {
        
        self.timeLab.text = @"刚刚";
    }else{
        self.timeLab.text = [CommonClass timestampToString:model.TimeStamp];
        
    }
    
    
    [self.browseBu setTitle:[NSString stringWithFormat:@"%ld",(long)model.IpReadCount] forState:UIControlStateNormal];
    
    [self.commentBu setTitle:[NSString stringWithFormat:@"%ld",(long)model.CommentCount] forState:UIControlStateNormal];
    
    [self.praiseBu setTitle:[NSString stringWithFormat:@"%ld",(long)model.ThumbupCount] forState:UIControlStateNormal];
    
    
//    if (self.isShow) {
//
//
//    }else{
//
//    }
    
    
    
//    if (model.IsAttended) {
//        self.reportBu.selected = YES;
//    }else{
//        self.reportBu.selected = NO;
//    }
    self.browseBu.hidden = YES;
    
    if (!self.isShow) {
        if (model.MatchId > 0) {
            
            _gameLabel.hidden = NO;
            NSString * gameStr = [NSString stringWithFormat:@"%@ vs %@",model.HomeTeamName,model.GuestTeamName];
            CGFloat w = [gameStr jk_widthWithFont:LSFontSize(10, LSScreenWidth) constrainedToHeight:18];
            _gameLabel.text = gameStr;
            _gameLabel.sd_layout
            .widthIs(w+10);
        }else{
            
            _gameLabel.hidden = YES;
        }
        
        if (![LSAccountArchive isLogin]) {
            self.reportBu.hidden = NO;
        }else{
            if ([[LSAccountArchive account].Cid isEqualToString:model.UserCid]) {
                self.reportBu.hidden = YES;
            }else{
                self.reportBu.hidden = NO;
            }

        }
    }else{
        _gameLabel.hidden = YES;
//        self.attentionBu.hidden = YES;
    }
    
}
- (void)setQueryCircleId:(NSInteger)queryCircleId{
    
//    _queryCircleId = queryCircleId;
//    if (queryCircleId == 0) {
//        self.browseBu.hidden = YES;
//        _gameLabel.hidden = NO;
//        self.timeLab.sd_resetLayout
//        .leftSpaceToView(_gameLabel, 5)
//        .centerYEqualToView(_gameLabel)
//        .autoHeightRatio(0);
//        [self.timeLab setSingleLineAutoResizeWithMaxWidth:180];
//    }else{
//        self.browseBu.hidden = NO;
//        _gameLabel.hidden = YES;
//        self.timeLab.sd_resetLayout
//        .leftSpaceToView(self.adressBu, 5)
//        .centerYEqualToView(self.adressBu)
//        .autoHeightRatio(0);
//        [self.timeLab setSingleLineAutoResizeWithMaxWidth:180];
//    }
    
}

- (void)ClickedImageView:(UITapGestureRecognizer *)tap{
    
    if (self.clickedImageViewBlock) {
        self.clickedImageViewBlock();
    }
}

-(void)reportEvent:(UIButton *)sender{
    if (self.block) {
       self.block(sender);
    }
//    sender.selected=!sender.selected;
    
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
@end



#pragma mark --LSChatCircleOneImageViewCell
@interface LSChatCircleOneImageViewCell()
@property(strong,nonatomic)UIImageView *headImageView;

@property(strong,nonatomic)UILabel *nickNameLabel;

@property(strong,nonatomic)UILabel *contentLabel;

@property(strong,nonatomic)UILabel *timeLabel;

@property(strong,nonatomic)UIButton *adressBtn;

@property(strong,nonatomic)UIButton *browseBtn;

@property(strong,nonatomic)UIButton *commentBtn;

@property(strong,nonatomic)UIButton *praiseBtn;

@property(nonatomic, strong) UIImageView * contentImageView;
@property(nonatomic, strong) EdgeInsetsLabel * gameLabel;
@end
@implementation LSChatCircleOneImageViewCell
+ (LSChatCircleOneImageViewCell *)ChatCircleOneImageViewCellByTableView:(UITableView *)tableView{
    LSChatCircleOneImageViewCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    if (!cell) {
        cell = [[LSChatCircleOneImageViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }

    return cell;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addContentView1];
    }
    return self;
}

- (void)addContentView1{
    
    UIImageView *headImageView=[[UIImageView alloc]init];
    headImageView.layer.masksToBounds=YES;
    headImageView.layer.cornerRadius=5;
    [self.contentView addSubview:headImageView];
    headImageView.userInteractionEnabled=YES;
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ClickedImageView:)];
    [headImageView addGestureRecognizer:tap];
    
    self.headImageView=headImageView;
    headImageView.sd_layout
    .leftEqualToView(self.contentView).offset(LSSpaceLeftWidth1)
    .topEqualToView(self.contentView).offset(12)
    .widthIs(30)
    .heightIs(30);
    
    _nickNameLabel=[[UILabel alloc]init];
    _nickNameLabel.font = LSFontSize11;
    _nickNameLabel.textColor = LSTitleGrayColor3;
    _nickNameLabel.textAlignment = NSTextAlignmentLeft;
    [self.contentView addSubview:_nickNameLabel];

    _nickNameLabel.sd_layout
    .leftSpaceToView(headImageView, 7)
    .centerYEqualToView(headImageView)
    .heightIs(20);
    [_nickNameLabel setSingleLineAutoResizeWithMaxWidth:120];
    
    _timeLabel = [[UILabel alloc] init];
    _timeLabel.font = LSFontSize10;
    
    _timeLabel.text = @"111";
    _timeLabel.textColor=LSTitleGrayColor3;
    [self.contentView addSubview:_timeLabel];
    _timeLabel.sd_layout
    .leftSpaceToView(_nickNameLabel, 10)
    .centerYEqualToView(_nickNameLabel)
    .heightIs(20);
    [_timeLabel setSingleLineAutoResizeWithMaxWidth:180];
    
    _reportBu=[[UIButton alloc]init];
    [_reportBu setImage:[UIImage imageNamed:@"delete"] forState:UIControlStateNormal];
//    [_attentionBu setImage:[UIImage imageNamed:@"selectAttend"] forState:UIControlStateSelected];
    [_reportBu addTarget:self action:@selector(reportEvent:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_reportBu];

    _reportBu.sd_layout
    .rightSpaceToView(self.contentView, 10)
    .centerYEqualToView(headImageView)
    .widthIs(20)
    .heightIs(20);
    
    _contentImageView = [[UIImageView alloc] init];
    [self.contentView addSubview:_contentImageView];
    _contentImageView.sd_layout
    .rightSpaceToView(self.contentView, 10)
    .topSpaceToView(_reportBu, 10)
    .widthIs((LSScreenWidth - 40) / 3)
    .heightIs((LSScreenWidth - 40) / 3 * 9/16);


    _contentLabel=[[UILabel alloc]init];
    _contentLabel.font=LSFontSize15;
    _contentLabel.textColor = LSSubColor5D5D5D;
    _contentLabel.textAlignment=NSTextAlignmentLeft;
    _contentLabel.numberOfLines = 4;
    [self.contentView addSubview:_contentLabel];
    _contentLabel.sd_layout
    .leftEqualToView(headImageView)
    .topSpaceToView(headImageView,10)
    .rightSpaceToView(_contentImageView, 10)
    .bottomEqualToView(_contentImageView);


    _adressBtn = [UIButton new];
    [_adressBtn setTitleColor:RGB(255,158,68) forState:UIControlStateNormal];
    _adressBtn.titleLabel.font=LSFontSize9;
    _adressBtn.layer.cornerRadius=5;
    _adressBtn.layer.masksToBounds=YES;
    _adressBtn.layer.borderColor=RGB(255,158,68).CGColor;
    _adressBtn.layer.borderWidth=.5f;
    [self.contentView addSubview:_adressBtn];

    _adressBtn.sd_layout
    .leftEqualToView(headImageView)
    .topSpaceToView(_contentLabel,9)
    .widthIs(45)
    .heightIs(18);


    EdgeInsetsLabel * gameLabel = [[EdgeInsetsLabel alloc] init];
    gameLabel.textColor = RGB(242, 94, 89);
    gameLabel.font = LSFontSize(10, LSScreenWidth);
    gameLabel.textAlignment = NSTextAlignmentCenter;
    gameLabel.text = @"皇家马德里 vs 毕尔巴鄂竞技";
    _gameLabel = gameLabel;
    gameLabel.layer.cornerRadius = 3;
    gameLabel.layer.borderColor = Color(242, 94, 89).CGColor;
    gameLabel.layer.borderWidth = 0.5;
    [self.contentView addSubview:gameLabel];
    gameLabel.sd_layout
    .leftSpaceToView(_adressBtn, 5)
    .centerYEqualToView(_adressBtn)
    .heightIs(18);
    //    [gameLabel setSingleLineAutoResizeWithMaxWidth:180];
    
    //    UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)




    _browseBtn=[UIButton new];
    [_browseBtn setTitleColor:LSTitleGrayColor3 forState:UIControlStateNormal];
    [_browseBtn setImage:[UIImage imageNamed:@"ChatBrowse"] forState:UIControlStateNormal];
    _browseBtn.titleLabel.font=LSFontSize10;
    [_browseBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, -10)];
    [self.contentView addSubview:_browseBtn];


    _commentBtn=[UIButton new];
    [_commentBtn setTitleColor:LSTitleGrayColor3 forState:UIControlStateNormal];
    [_commentBtn setImage:[UIImage imageNamed:@"ChatComment"] forState:UIControlStateNormal];
    _commentBtn.titleLabel.font=LSFontSize10;
    [_commentBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, -10)];
    [self.contentView addSubview:_commentBtn];


    _praiseBtn=[UIButton new];
    [_praiseBtn setTitleColor:LSTitleGrayColor3 forState:UIControlStateNormal];
    [_praiseBtn setImage:[UIImage imageNamed:@"ChatPraise"] forState:UIControlStateNormal];
    _praiseBtn.titleLabel.font=LSFontSize10;
    [_praiseBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, -10)];
    [self.contentView addSubview:_praiseBtn];

    _praiseBtn.sd_layout
    .rightEqualToView(self.contentView).offset(-LSSpaceLeftWidth1)
    .centerYEqualToView(_adressBtn)
    .heightIs(25)
    .widthIs(50);
    //    [praiseBu set]


    _commentBtn.sd_layout
    .rightSpaceToView(_praiseBtn, -7)
    .centerYEqualToView(_adressBtn)
    .widthIs(50)
    .heightIs(25);

    _browseBtn.sd_layout
    .rightSpaceToView(_commentBtn, -7)
    .centerYEqualToView(_adressBtn)
    .widthIs(50)
    .heightIs(25);

    UIView * bottomView = [[UIView alloc] init];
    bottomView.backgroundColor = LSBackGroundColor;
    [self.contentView addSubview:bottomView];
    bottomView.sd_layout
    .leftEqualToView(self.contentView)
    .rightEqualToView(self.contentView)
    .topSpaceToView(_praiseBtn, 10)
    .heightIs(10);
    
    [self setupAutoHeightWithBottomView:bottomView bottomMargin:0];
    
}
- (void)ClickedImageView:(UITapGestureRecognizer *)tap{
    
    if (self.clickedImageViewBlock) {
        self.clickedImageViewBlock();
    }
}

-(void)reportEvent:(UIButton *)sender{
    if (self.block) {
        self.block(sender);
    }
    //    sender.selected=!sender.selected;
    
}
- (void)setModel:(LSChatCircleModel *)model{
    _model = model;
    [_contentImageView sd_setImageWithURL:[NSURL URLWithString:model.ImgUrlStr] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {

    }];
//    self.adressBu.sd_resetLayout
//    .leftEqualToView(self.headImageView)
//    .topSpaceToView(self.photoView,9)
//    .widthIs(60)
//    .heightIs(20);

    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:model.UserHeadUrl] placeholderImage:[UIImage imageNamed:@"MineDefaultHead"] options:SDWebImageRefreshCached];
    _nickNameLabel.text = model.UserDisName;

    _contentLabel.text = model.TopicContent;

    [_adressBtn setTitle:model.CircleName forState:UIControlStateNormal];
    NSString * timeStr = [model.CreateTime stringByReplacingOccurrencesOfString:@"T" withString:@" "];

    NSDateFormatter * df = [[NSDateFormatter alloc] init];
    df.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    NSString * dateString1 = timeStr;
    NSString * dateString2 = [CommonClass getCurrentTimes];
    NSDate * date1 = [df dateFromString:dateString1];
    NSDate * date2 = [df dateFromString:dateString2];
    NSTimeInterval time = [date2 timeIntervalSinceDate:date1]; //date1是前一个时间(早)，date2是后一个时间(晚)
    // 结果就是两个时间点之间相差的秒数，如果要精确时间，修改NSDateFormatter的形式，并把两个时间对应调整就行
    if (time < 300) {

        _timeLabel.text = @"刚刚";
    }else{
        _timeLabel.text = [CommonClass timestampToString:model.TimeStamp];

    }


    [_browseBtn setTitle:[NSString stringWithFormat:@"%ld",(long)model.ReadCount] forState:UIControlStateNormal];

    [_commentBtn setTitle:[NSString stringWithFormat:@"%ld",(long)model.CommentCount] forState:UIControlStateNormal];

    [_praiseBtn setTitle:[NSString stringWithFormat:@"%ld",(long)model.ThumbupCount] forState:UIControlStateNormal];


    if (![LSAccountArchive isLogin]) {
        self.reportBu.hidden = NO;
    }else{
        if ([[LSAccountArchive account].Cid isEqualToString:model.UserCid]) {
            self.reportBu.hidden = YES;
        }else{
            self.reportBu.hidden = NO;
        }


    }

//    if (model.IsAttended) {
//        self.attentionBu.selected = YES;
//    }else{
//        self.attentionBu.selected = NO;
//    }
    _browseBtn.hidden = YES;
    if (model.MatchId > 0) {

        _gameLabel.hidden = NO;
        NSString * gameStr = [NSString stringWithFormat:@"%@ vs %@",model.HomeTeamName,model.GuestTeamName];
//        NSMutableAttributedString * attributeStr = [CommonClass htmlStrTraslateNormalStrWithHtml:gameStr Withfont:LSFontSize(10, LSScreenWidth) withColor:RGB(242, 94, 89)];
//        _gameLabel.attributedText = attributeStr;
        _gameLabel.text = gameStr;
        CGFloat w = [gameStr jk_widthWithFont:LSFontSize(10, LSScreenWidth) constrainedToHeight:18];
        
        _gameLabel.sd_layout
        .widthIs(w+20);
        _gameLabel.contentInset = UIEdgeInsetsMake(3,3, 3, 3);
    }else{

        _gameLabel.hidden = YES;
    }
}

@end


#pragma mark -- LSChatCirclePartakeCell
@interface LSChatCirclePartakeCell()
@property(strong,nonatomic)UIImageView *headImageView;

@property(strong,nonatomic)UILabel *nameLab;

@property(strong,nonatomic)UILabel *contentLab;

@property(strong,nonatomic)UILabel *introduceLab;

@property(strong,nonatomic)UILabel *timeLab;

@property(strong,nonatomic)UIButton *adressBu;

@property(strong,nonatomic)UIButton *browseBu;

@property(strong,nonatomic)UIButton *commentBu;

@property(strong,nonatomic)UIButton *praiseBu;

@property(nonatomic, strong) LSChatPhotoView * photoView;
@end

@implementation LSChatCirclePartakeCell

+ (LSChatCirclePartakeCell *)ChatCirclePartakeTableViewCellByTableView:(UITableView *)tableView{
    LSChatCirclePartakeCell * cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(self)];
    if (!cell) {
        cell = [[LSChatCirclePartakeCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass(self)];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    
    
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addContentView];
    }
    return self;
}

- (void)addContentView{
    
    UIImageView *headImageView=[[UIImageView alloc]init];
    headImageView.layer.masksToBounds=YES;
    headImageView.layer.cornerRadius=2;
    [self.contentView addSubview:headImageView];
    headImageView.userInteractionEnabled=YES;
    UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ClickedImageView:)];
    [headImageView addGestureRecognizer:tap];
    
    
    self.headImageView=headImageView; headImageView.sd_layout.leftEqualToView(self.contentView).offset(LSSpaceLeftWidth1).topEqualToView(self.contentView).offset(12).widthIs(30).heightIs(30);
    
    UILabel *nameLab=[[UILabel alloc]init];
    nameLab.font=LSFontSize11;
    nameLab.textColor=LSTitleGrayColor3;
    nameLab.textAlignment=NSTextAlignmentLeft;
    [self.contentView addSubview:nameLab];
    self.nameLab=nameLab;
    nameLab.sd_layout.leftSpaceToView(headImageView, 7).centerYEqualToView(headImageView).heightIs(20).autoWidthRatio(6);
    
    UIButton *attentionBu=[[UIButton alloc]init];
    attentionBu.titleLabel.textColor=LSTitleWhiteColor;
    attentionBu.titleLabel.font=LSFontSize10;
    [attentionBu setBackgroundImage:[CommonClass getImageWithBgColor:LSButtonColor] forState:UIControlStateNormal];
    [attentionBu setBackgroundImage:[CommonClass getImageWithBgColor:LSButtonColor] forState:UIControlStateHighlighted];
    attentionBu.selected=NO;
    [attentionBu setTitle:@"+关注" forState:UIControlStateNormal];
    [attentionBu setTitle:@"取消关注" forState:UIControlStateSelected];
    attentionBu.layer.masksToBounds=YES;
    attentionBu.layer.cornerRadius=8;
    [attentionBu addTarget:self action:@selector(attentionEvent:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:attentionBu];
    self.attentionBu=attentionBu;
    attentionBu.sd_layout.rightEqualToView(self.contentView).offset(-LSSpaceLeftWidth1).centerYEqualToView(headImageView).widthIs(50).heightIs(16);
    
 
    UILabel *contentLab=[[UILabel alloc]init];
    contentLab.font=LSFontSize15;
    contentLab.textColor = LSSubColor5D5D5D;
    contentLab.textAlignment=NSTextAlignmentLeft;
    contentLab.numberOfLines=2;
    [self.contentView addSubview:contentLab];
    self.contentLab=contentLab;
    contentLab.sd_layout.leftEqualToView(headImageView).topSpaceToView(headImageView,0).rightEqualToView(self.contentView).offset(-LSSpaceLeftWidth1).heightIs(40);
    
    
    UIView * backView1 = [[UIView alloc] init];
    backView1.backgroundColor = Color(213, 213, 213);
    [self.contentView addSubview:backView1];
    backView1.sd_layout.leftEqualToView(headImageView).topSpaceToView(contentLab,0).rightEqualToView(self.contentView).offset(-LSSpaceLeftWidth1).heightIs(40);
    backView1.sd_cornerRadius = [[NSNumber alloc] initWithFloat:3.0];
    backView1.layer.masksToBounds=YES;
    
    UILabel *introduceLab=[[UILabel alloc]init];
    introduceLab.font=LSFontSize15;
    introduceLab.textColor = LSSubColor5D5D5D;
    introduceLab.textAlignment=NSTextAlignmentLeft;
    introduceLab.numberOfLines=2;
    [self.contentView addSubview:introduceLab];
    self.introduceLab=introduceLab;
    introduceLab.sd_layout.leftEqualToView(headImageView).topSpaceToView(contentLab,0).rightEqualToView(self.contentView).offset(-LSSpaceLeftWidth1).heightIs(40);
    
    _photoView = [[LSChatPhotoView alloc] init];
    [self.contentView addSubview:_photoView];
    _photoView.sd_layout.leftEqualToView(headImageView).topSpaceToView(_introduceLab, 5); // 已经在内部实现宽度和高度自适应所以不需要再设置宽度高度，top值是具体有无图片在setModel方法中设置
    
    UIButton *adressBu=[UIButton new];
    [adressBu setTitleColor:Color(253, 140, 53) forState:UIControlStateNormal];
    adressBu.titleLabel.font=LSFontSize13;
    adressBu.layer.cornerRadius=5;
    adressBu.layer.masksToBounds=YES;
    adressBu.layer.borderColor=Color(253, 140, 53).CGColor;
    adressBu.layer.borderWidth=.5f;
    [self.contentView addSubview:adressBu];
    self.adressBu=adressBu;
    adressBu.sd_layout.leftEqualToView(headImageView).topSpaceToView(_photoView,9).widthIs(60).heightIs(20);
    
    
    UILabel *timeLab=[[UILabel alloc]init];
    timeLab.font=LSFontSize10;
    timeLab.textColor=LSTitleGrayColor3;
    timeLab.textAlignment=NSTextAlignmentLeft;
    [self.contentView addSubview:timeLab];
    self.timeLab=timeLab;
    timeLab.sd_layout.leftEqualToView(headImageView).topSpaceToView(adressBu,0).heightIs(20).autoWidthRatio(10);
    [self setupAutoHeightWithBottomView:self.timeLab bottomMargin:10];
}

- (void)ClickedImageView:(UITapGestureRecognizer *)tap{
    
    if (self.clickedImageViewBlock) {
        self.clickedImageViewBlock();
    }
}

- (void)setModel:(LSChatCircleModel *)model{
    _model = model;
    if (model.ImgUrlStr.length <= 0) {
//        self.adressBu.sd_resetLayout.leftEqualToView(self.headImageView).topSpaceToView(self.introduceLab,9).widthIs(60).heightIs(20);
//        self.photoView.hidden = YES;
        self.photoView.picPathStringsArray = @[];
    }else{
//        self.photoView.hidden = NO;
//        self.adressBu.sd_resetLayout.leftEqualToView(self.headImageView).topSpaceToView(self.photoView,9).widthIs(60).heightIs(20);
        NSArray * array = [model.ImgUrlStr componentsSeparatedByString:@","];
        self.photoView.picPathStringsArray = array;
        
    }
    
    
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:model.UserHeadUrl] placeholderImage:[UIImage imageNamed:@"MineDefaultHead"] options:SDWebImageRefreshCached];
//    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:model.UserHeadUrl] placeholderImage:@""];
//    self.nameLab.text = model.DisplayName;
    
    
    NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
    // 对齐方式
    style.alignment = NSTextAlignmentJustified;
    // 首行缩进
    style.firstLineHeadIndent = 10.0f;
    // 头部缩进
    style.headIndent = 10.0f;
    // 尾部缩进
    style.tailIndent = -10.0f;
    NSAttributedString *attrText = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"【话题】%@",model.TopicContent] attributes:@{ NSParagraphStyleAttributeName : style}];
    self.introduceLab.attributedText = attrText;
    
    NSAttributedString *attrText1 = [[NSAttributedString alloc] initWithString:model.MainContent attributes:@{ NSParagraphStyleAttributeName : style}];
    self.contentLab.attributedText = attrText1;
    
    [self.adressBu setTitle:model.CircleName forState:UIControlStateNormal];
    
    NSString * timeStr = [model.CreateTime stringByReplacingOccurrencesOfString:@"T" withString:@" "];
    
    NSDateFormatter * df = [[NSDateFormatter alloc] init];
    df.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    NSString * dateString1 = timeStr;
    NSString * dateString2 = [CommonClass getCurrentTimes];
    NSDate * date1 = [df dateFromString:dateString1];
    NSDate * date2 = [df dateFromString:dateString2];
    NSTimeInterval time = [date2 timeIntervalSinceDate:date1]; //date1是前一个时间(早)，date2是后一个时间(晚)
    // 结果就是两个时间点之间相差的秒数，如果要精确时间，修改NSDateFormatter的形式，并把两个时间对应调整就行
    if (time < 300) {
        
        self.timeLab.text = @"刚刚";
    }else{
        self.timeLab.text = [CommonClass timestampToString:model.TimeStamp];
        
    }
    
   
  
}

@end




